-- encoding: utf-8
-- 本文件中的日期代码由网友“镜中的迷离”倾情奉献
-- 阿拉伯数字转小写代码由网友“风箫箫”倾情奉献。
-- 外部程序调用代码由“无关风月”倾情奉献。
-- 深山红叶合成、整理
-- Usage:
--  engine:
--    ...
--    translators:
--      ...
--      - lua_translator@lua_function3
--      - lua_translator@lua_function4
--      ...
--    filters:
--      ...
--      - lua_filter@lua_function1
--      - lua_filter@lua_function2
--      ...
--    请在方案配置文件比如wubi86.schema.yaml的engine\translators:下面添加滤镜引用：
--      - lua_translator@date_translator
--      - lua_translator@week_translator
function command_translator(input, seg) 
    if (input == "/calcl") then  --打开计算器
    strProgram = '"C:\\Windows\\system32\\calc.exe"' 
    strCmd = 'start "" '..strProgram 
    os.execute(strCmd)
   end
   if (input == "/controll") then  --打开控制面板
    strProgram = '"C:\\Windows\\system32\\control.exe"' 
    strCmd = 'start "" '..strProgram 
    os.execute(strCmd)
   end
   if (input == "/conl") then  --打开控制面板
    strProgram = '"C:\\Windows\\system32\\control.exe"' 
    strCmd = 'start "" '..strProgram 
    os.execute(strCmd)
   end
   if (input == "/appl") then  --程序和功能
    strProgram = '"C:\\Windows\\system32\\appwiz.cpl"' 
    strCmd = 'start "" '..strProgram 
    os.execute(strCmd)
   end
   if (input == "/cmdl") then  --打开cmd
    strProgram = '"c:\\Windows\\System32\\cmd.exe"' 
    strCmd = 'start "" '..strProgram 
    os.execute(strCmd)
   end
   if (input == "/notepadl") then  --打开notepad
    strProgram = '"c:\\Windows\\System32\\notepad.exe"' 
    strCmd = 'start "" '..strProgram 
    os.execute(strCmd)
   end
   if (input == "/paintl") then  --打开 画图
    strProgram = '"c:\\Windows\\System32\\mspaint.exe"' 
    strCmd = 'start "" '..strProgram 
    os.execute(strCmd)
   end
   if (input == "/iel") then  --打开 画图
    strProgram = '"C:\\Program Files\\Internet Explorer\\iexplore.exe"' 
    strCmd = 'start "" '..strProgram 
    os.execute(strCmd)
   end
end
function date_translator(input, seg)
    if (input == "dd") then
       --- Candidate(type, start, end, text, comment)
       yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), ""))
       yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
    end
   if (input == "ww") then
      arr = {"一","二","三","四","五","六"}
      arr[0] = "日"
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d 星期"..arr[tonumber(os.date("%w"))]), ""))
   end
   if (input == "tt") then
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d %H:%M:%S"), ""))
      yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), ""))
   end
 end
 
 --- 过滤器：单字在先
 function single_char_first_filter(input)
    local l = {}
    for cand in input:iter() do
       if (utf8.len(cand.text) == 1) then
          yield(cand)
       else
          table.insert(l, cand)
       end
    end
    for i, cand in ipairs(l) do
       yield(cand)
    end
 end
